﻿using System;
using System.Collections.Generic;
using FineUI;
using SDLITS.Common;
using SDLITS.Model;
using System.Configuration;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace SDLITS.Web.SystemManage
{
    public class ModelCompanyMemberPrint
    {
        public string StartDate { get; set; }
        public string ExpireDate { get; set; }
        public string MemType { get; set; }
        public string WorkAmount { get; set; }
        public string InitialAmount { get; set; }
        public string Worker { get; set; }
        public string MemCardNo { get; set; }
    }
    public partial class CompanyMemberManage : CommonBase
    {
        #region Private Field
        public DataSet Ds;
        public enum EnumActionType
        {
            AddCompanyCard,
            ChangeCompanyCard
        }

        public static string AppServer = ConfigurationManager.AppSettings["AppServer"];
        public static readonly string IDShotPath = string.Format(@"\\{0}\IDShot\", AppServer);
        public static readonly string CamShotPath = string.Format(@"\\{0}\CamShot\", AppServer);


        public static readonly string IDShotPathFinal = @"/Img/IDShot/";
        public static readonly string CamShotPathFinal = @"/Img/CamShot/";

        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindCom();
                hidCamShotTimesnap.Text = DateTime.Now.ToString().Replace(" ", "").Replace("-", "").Replace(":", "").Replace("/", "");
                hidMapPath1.Text = @"/Img/IDShotTemp/";
                hidMapPath1p.Text = string.Format(@"\\{0}\IDShotTemp\", AppServer);
                hidMapPath3.Text = @"/Img/CamShotTemp/";
                hidMapPath3p.Text = string.Format(@"\\{0}\CamShotTemp\", AppServer);
            }
        }
        protected void BindCom()
        {
            SqlParameter[] sp = new SqlParameter[]{
                    new SqlParameter("@SPAction","SelectAll")
                };
            DataSet ds = SDDbSession.Default.FromProc("TableCompany").AddParameter(sp).ToDataSet();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ListItem li = new ListItem();
                    li.Text = string.Format("{0} ({1})", ds.Tables[0].Rows[i]["Value"], ds.Tables[0].Rows[i]["RoomNo"]);
                    li.Value = ds.Tables[0].Rows[i]["ID"].ToString();
                    cmbCompanyRoom.Items.Add(li);
                }
            }
            cmbCompanyRoom.Items.Insert(0, new ListItem("--请选择公司--", "-1"));
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (ViewState["IsSelect"] != null)
            {
                ChangeBtnStatus();
                if (!string.IsNullOrEmpty(lblIDNumber.Text))
                {
                    if ((EnumActionType)ViewState["CurrentAction"] != EnumActionType.ChangeCompanyCard)
                    {
                        imgIDShot.ImageUrl = string.Format("{1}{2}/{0}.bmp", lblIDNumber.Text, hidMapPath1.Text, hidIDShotTimesnap.Text);
                        if (!Methed.CheckCard(lblIDNumber.Text, null))
                        {
                            lbtnSubmit.Hidden = true;
                            Alert.Show("此身份证已关联到其它出入卡");
                            return;
                        }
                    }
                    lbtnSubmit.Hidden = false;

                    if (ViewState["IsRead"] != null)
                    {
                        dataPersonal.Hidden = false;
                    }
                }
            }
        }
        private void BindGrid(DataSet dataSet)
        {
            if (dataSet != null && dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0)
            {
                Grid1.DataSource = dataSet.Tables[0];
                Grid1.DataBind();
            }
            else
            {
                Grid1.DataSource = null;
                Grid1.DataBind();
            }
        }
        protected void btnReset_Click(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(lblIDNumber.Text))
            //{
            //    Alert.Show("身份证读取失败，请重试");
            //    imgIDShot.ImageUrl = "../Img/photoTemp.jpg";
            //    imgCam.ImageUrl = "../Img/photoTemp.jpg";
            //    return;
            //}
            //if (ViewState["IDNumber"] != null && ViewState["IDNumber"].ToString().Equals(lblIDNumber.Text))
            //{
            //    imgIDShot.ImageUrl = string.Format("{0}{1}.bmp", IDShotPathFinal, lblIDNumber.Text);
            //    imgCam.ImageUrl = string.Format("{0}{1}.jpg", CamShotPathFinal, lblIDNumber.Text);
            //}
            //else
            //{
            //    imgIDShot.ImageUrl = string.Format("{1}{2}/{0}.bmp", lblIDNumber.Text, hidMapPath1.Text,
            //                                       hidIDShotTimesnap.Text);
            //    imgCam.ImageUrl = string.Format("{0}{1}{2}.jpg", hidMapPath3p.Text, lblIDNumber.Text,
            //                                    hidCamShotTimesnap.Text);
            //}
            if (string.IsNullOrEmpty(lblIDNumber.Text))
            {
                Alert.Show("身份证号不能为空！");
                return;
            }
            btnCamer.OnClientClick = Window2.GetShowReference("/Driver/CameraPhoto.aspx?id=" + lblIDNumber.Text);

            ViewState["IsRead"] = true;
        }
        protected void cmbCompanyRoom_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbCompanyRoom.SelectedValue != "-1")
            {
                ClearAllStatus();
                ClearControl();
                InitAllFields();

                Ds = GetDataList();
                //spanDataList.Hidden = false;
                if (Ds != null && Ds.Tables.Count > 0)
                {
                    ViewState["IsSelect"] = true;
                    BindGrid(Ds);
                    ViewState["MemType"] = 3;
                }
            }
        }
        private DataSet GetDataList()
        {
            if (cmbCompanyRoom.SelectedValue == "-1")
            {
                Alert.Show("请选择正确的公司！");
                return null;
            }
            string str = "SELECT mc.*,mi.RegistID,mi.Name FROM [MemCard] as mc left join [MemberInfo] as mi on mc.MemCardID=mi.MemCardID where mc.CompanyID=" + cmbCompanyRoom.SelectedValue + " and mc.StatusID=1";
            DataSet ds = SDDbSession.Default.FromSql(str).ToDataSet();
            return ds;
        }
        protected void lbtnAddDriverCard_Click(object sender, EventArgs e)
        {
            SqlParameter[] sp = new SqlParameter[]{
                    new SqlParameter("@CompanyID",Convert.ToInt32(cmbCompanyRoom.SelectedValue)),
                    new SqlParameter("@SPAction","SelectLastByCompanyID")
                };
            DataSet Ds = SDDbSession.Default.FromProc("TableContract").AddParameter(sp).ToDataSet();
            if (Ds != null && Ds.Tables.Count > 0 && Ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = Ds.Tables[0].Rows[0];
                if (Convert.ToInt32(dr["CompanyCardVol"]) <= Grid1.Rows.Count)
                {
                    Alert.Show("超过此企业允许拥有的最大持卡量！");
                    return;
                }
                if (Convert.ToDateTime(dr["EndDate"]) <= DateTime.Now)
                {
                    Alert.Show("企业合同已经到期！");
                    return;
                }
                GroupPanel5.Hidden = false;
                spanDataList.Hidden = true;
                lblStartDate.Text = dr["StartDate"].ToString();
                lblExpireDate.Text = dr["EndDate"].ToString();
                ViewState["CurrentAction"] = EnumActionType.AddCompanyCard;
            }
            else
            {
                Alert.Show("还没有签订添加企业合同！");
                Response.Redirect("~/Customer/CompanyManage.aspx");
            }
        }
        protected void lbtnModifyCard_Click(object sender, EventArgs e)
        {

            int[] selections = Grid1.SelectedRowIndexArray;
            if (selections.Length > 0)
            {
                cmbCompanyRoom.Enabled = false;
                ViewState["CurrentAction"] = EnumActionType.ChangeCompanyCard;
                foreach (int rowIndex in selections)
                {
                    int id = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]);
                    ViewState["MemCardID"] = id;
                    SqlParameter[] sp = new SqlParameter[]{
                    new SqlParameter("@MemCardID",id),
                    new SqlParameter("@SPAction","SelectAllByMemCardID")
                };
                    DataSet Ds = SDDbSession.Default.FromProc("TableMemberInfo").AddParameter(sp).ToDataSet();
                    if (Ds != null && Ds.Tables.Count > 0 && Ds.Tables[0].Rows.Count > 0)
                    {

                        BindGrid(Ds);
                        DataRow dr = Ds.Tables[0].Rows[0];

                        ViewState["MemberID"] = dr["MemberID"];

                        lblIDNumber.Text = dr["IDNumber"] is DBNull ? "" : dr["IDNumber"].ToString();
                        ViewState["IDNumber"] = lblIDNumber.Text;
                        lblSex.Text = dr["Sex"].Equals("False") ? "女" : "男";
                        lblIDAddress.Text = dr["IDAddress"] is DBNull ? "" : dr["IDAddress"].ToString();
                        if (!(dr["Birthday"] is DBNull))
                        {
                            lblBirthday.SelectedDate = Convert.ToDateTime(dr["Birthday"]);
                        }
                        lblName.Text = dr["Name"] is DBNull ? "" : dr["Name"].ToString();


                        txtMemCardNo.Text = dr["MemCardNo"] is DBNull ? "" : dr["MemCardNo"].ToString();
                        lblStartDate.Text = dr["StartDate"] is DBNull ? "" : dr["StartDate"].ToString();
                        lblExpireDate.Text = dr["ExpireDate"] is DBNull ? "" : dr["ExpireDate"].ToString();
                        txtCell.Text = dr["Cell"] is DBNull ? "" : dr["Cell"].ToString();
                        txtPhone.Text = dr["Phone"] is DBNull ? "" : dr["Phone"].ToString();

                        imgIDShot.ImageUrl = string.Format("{0}{1}.bmp", IDShotPathFinal, lblIDNumber.Text);
                        imgCam.ImageUrl = string.Format("{0}{1}.jpg", CamShotPathFinal, lblIDNumber.Text);
                    }
                }
                ViewState["IsRead"] = true;
            }
            else
                Alert.Show("未选中要更新的项！");


        }

        protected void lbtnFreeCard_Click(object sender, EventArgs e)
        {
            int[] selections = Grid1.SelectedRowIndexArray;
            if (selections.Length > 0)
            {
                foreach (int rowIndex in selections)
                {
                    string id = Grid1.DataKeys[rowIndex][0].ToString();
                    int result = 0;
                    result += SDDbSession.Default.FromSql("UPDATE [MemCard] SET [StatusID] = 3 WHERE [MemCardID]= " + id).ExecuteNonQuery();
                    result += SDDbSession.Default.FromSql("INSERT INTO [MemCardHistory]([MemberID],[MemCardID],[CreateDate]) VALUES((Select MemberID from MemberInfo where MemCardID=" + id + ")," + id + ",'" + DateTime.Now + "')").ExecuteNonQuery();
                    result += SDDbSession.Default.FromSql("UPDATE [MemberInfo] SET [MemCardID] = 0 WHERE [MemCardID]= " + id).ExecuteNonQuery();
                    if (result == 0)
                    {
                        Alert.Show("冻结选中记录时发生错误！请重试！");
                        return;
                    }
                }
                Alert.Show("冻结选中的卡数据成功", "提示", "window.location.reload()");
            }
            else

                Alert.Show("未选中任何记录信息", "提示");
        }

        protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
        {
            e.Values[2] = Methed.Status(e.Values[2].ToString());
        }

        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid(Ds);
        }
        private void ChangeBtnStatus()
        {
            InitAllFields();
            //  spanDataList.Hidden = false;
            if (ViewState["CurrentAction"] == null)
            {
                //spanActions.Visible = true;
                lbtnAddCard.Hidden = false;
                lbtnModifyCard.Hidden = false;
                lbtnFreeCard.Hidden = false;
                spanDataList.Hidden = false;
                // lbtnSubmit.Hidden = false;
            }
            else
            {
                spanIdentity.Hidden = false;
            }
        }
        private void InitAllFields()
        {
            //spanActions.Hidden = true;
            lbtnAddCard.Hidden = true;
            lbtnModifyCard.Hidden = true;
            lbtnFreeCard.Hidden = true;
            lbtnSubmit.Hidden = true;

            lbtnSubmit.Hidden = true;
            spanIdentity.Hidden = true;
            spanDataList.Hidden = true;
            dataPersonal.Hidden = true;
        }
        private void ClearAllStatus()
        {
            ViewState["IsRead"] = null;
            ViewState["IsSelect"] = null;
            ViewState["MemType"] = null;
            ViewState["MemCardID"] = null;
            ViewState["MemCardNo"] = null;
            ViewState["CurrentAction"] = null;
            ViewState["IDNumber"] = null;
        }

        private void ClearControl()
        {
            if (!string.IsNullOrEmpty(lblIDNumber.Text))
            {
                File.Delete(string.Format("{0}{1}.bmp", hidMapPath1p.Text, lblIDNumber.Text));
            }

            txtMemCardNo.Text = "";
            lblStartDate.Text = "";
            lblExpireDate.Text = "";
            txtCell.Text = "";
            txtPhone.Text = "";

            lblIDNumber.Text = "";
            lblName.Text = "";
            lblIDAddress.Text = "";
            lblSex.Text = "";
            lblBirthday.Text = "";
            imgIDShot.ImageUrl = "../Img/photoTemp.jpg";
        }
        protected void lbtnSubmitDriver_Click(object sender, EventArgs e)
        {
            //cmbCompanyRoom.Enabled = true;
            string initialAmount = GetInitialAmount();
            string workAmount = GetWorkAmount();
            switch ((EnumActionType)ViewState["CurrentAction"])
            {
                case EnumActionType.AddCompanyCard:
                    if (txtMemCardNo.Text != "")
                    {
                        if (AddCardInfo())
                        {
                            RechargeInit(initialAmount, "0");
                            Alert.Show("企业卡添加成功！", "提示", "window.location.reload()");
                            ViewState["IsSelect"] = null;
                            ViewState["IsRead"] = null;
                            Print();
                            return;
                        }
                        Alert.Show("企业卡添加失败，企业卡已经存在！");
                    }
                    else
                        Alert.Show("请输入卡号！");
                    break;
                case EnumActionType.ChangeCompanyCard:
                    if (ModifyCardInfo())
                    {
                        Alert.Show("企业卡更新成功！", "提示", "window.location.reload()");
                        ViewState["IsSelect"] = null;
                        ViewState["IsRead"] = null;
                        return;
                    }
                    Alert.Show("企业卡更新失败！可能此身份证已关联到其它出入卡！");
                    break;
            }

        }
        public string GetInitialAmount()
        {
            MasterDic md = SDDbSession.Default.From<MasterDic>().ToFirst();
            if (md != null)
            {
                return md.InitialAmount.ToString();
            }
            return "0";
        }
        public string GetWorkAmount()
        {
            MasterDic md = SDDbSession.Default.From<MasterDic>().ToFirst();
            if (md != null)
            {
                return md.WorkAmount.ToString();
            }
            return "0";
        }

        #region Member Card
        private bool AddCardInfo()
        {
            SqlParameter[] sp = new SqlParameter[]{
                    new SqlParameter("@MemCardNo",txtMemCardNo.Text),
                    new SqlParameter("@StatusID",1),
                    new SqlParameter("@CompanyID",Convert.ToInt32(cmbCompanyRoom.SelectedValue)),
                    new SqlParameter("@MemTypeID",3),
                    new SqlParameter("@SPAction","Insert")
                };
            int newID = int.Parse(SDDbSession.Default.FromProc("TableMemCard").AddParameter(sp).ToScalar().ToString());//.ExecuteNonQuery();
            if (newID < 1)
            {
                return false;
            }
            ViewState["MemCardID"] = newID;
            ViewState["MemCardNo"] = txtMemCardNo.Text;

            string birthday = lblBirthday.Text.Trim();
            if (string.IsNullOrEmpty(birthday))
            {
                birthday = "1900-01-01";
            }
            SqlParameter[] sp2 = new SqlParameter[]{
                    new SqlParameter("@RegistID",GetRegistID()),
                    new SqlParameter("@Name",lblName.Text.Trim()),
                    new SqlParameter("@Sex",Convert.ToBoolean(lblSex.Text.Equals("男"))),
                    new SqlParameter("@Birthday",Convert.ToDateTime(birthday)),
                    new SqlParameter("@IDNumber",lblIDNumber.Text.Trim()),
                    new SqlParameter("@IDAddress",lblIDAddress.Text.Trim()),
                    new SqlParameter("@Cell",txtCell.Text.Trim()),
                    new SqlParameter("@Phone",txtPhone.Text.Trim()),
                    new SqlParameter("@MemCardID",newID),
                    new SqlParameter("@IDShot",string.Format("{0}{1}.bmp", IDShotPathFinal, lblIDNumber.Text)),
                    new SqlParameter("@CamShot",string.Format("{0}{1}.jpg", CamShotPathFinal, lblIDNumber.Text)),
                    new SqlParameter("@SPAction","Insert")
                };
            int result = int.Parse(SDDbSession.Default.FromProc("TableMemberInfo").AddParameter(sp2).ToScalar().ToString());//.ExecuteNonQuery();
            if (result > 0)
            {
                SqlParameter[] sp3 = new SqlParameter[]{
                    new SqlParameter("@MemCardID",newID),
                    new SqlParameter("@RegistID",GetRegistID()),
                    new SqlParameter("@Name",lblName.Text.Trim()),
                    new SqlParameter("@Sex",Convert.ToBoolean(lblSex.Text.Equals("男"))),
                    new SqlParameter("@Birthday",Convert.ToDateTime(birthday)),
                    new SqlParameter("@IDNumber",lblIDNumber.Text.Trim()),
                    new SqlParameter("@IDAddress",lblIDAddress.Text.Trim()),
                    new SqlParameter("@Cell",txtCell.Text.Trim()),
                    new SqlParameter("@Phone",txtPhone.Text.Trim()),
                    new SqlParameter("@IDShot",string.Format("{0}{1}.bmp", IDShotPathFinal, lblIDNumber.Text)),
                    new SqlParameter("@CamShot",string.Format("{0}{1}.jpg", CamShotPathFinal, lblIDNumber.Text)),
                    new SqlParameter("@SPAction","UpdateByIDNumber")
                };
                int result2 = SDDbSession.Default.FromProc("TableMemberInfo").AddParameter(sp3).ExecuteNonQuery();
                //if (result2<1)
                //{
                //    return false;
                //}
            }

            //MovePhoto();
            return true;
        }
        private bool ModifyCardInfo()
        {
            if (Methed.CheckCard(lblIDNumber.Text, null) || ViewState["IDNumber"].ToString().Equals(lblIDNumber.Text))
            {
                MemCard mc = new MemCard();
                mc.Attach();
                mc.MemCardID = Convert.ToInt32(ViewState["MemCardID"]);
                mc.MemCardNo = txtMemCardNo.Text;
                mc.MemTypeID = 3;
                int result1 = SDDbSession.Default.Update(mc);
                if (result1 < 1)
                {
                    return false;
                }

                string birthday = lblBirthday.Text.Trim();
                if (string.IsNullOrEmpty(birthday))
                {
                    birthday = "1900-01-01";
                }
                SqlParameter[] sp3 = new SqlParameter[]{
                    new SqlParameter("@MemberID",Convert.ToInt32(ViewState["MemberID"])),
                    new SqlParameter("@MemCardID",Convert.ToInt32(ViewState["MemCardID"])),
                    new SqlParameter("@IDNumber",lblIDNumber.Text.Trim()),
                    new SqlParameter("@Name",lblName.Text.Trim()),
                    new SqlParameter("@Sex",Convert.ToBoolean(lblSex.Text.Equals("男"))),
                    new SqlParameter("@Birthday",Convert.ToDateTime(birthday)),
                    new SqlParameter("@IDAddress",lblIDAddress.Text.Trim()),
                    new SqlParameter("@Cell",txtCell.Text.Trim()),
                    new SqlParameter("@Phone",txtPhone.Text.Trim()),
                    new SqlParameter("@IDShot",string.Format("{0}{1}.bmp", IDShotPathFinal, lblIDNumber.Text)),
                    new SqlParameter("@CamShot",string.Format("{0}{1}.jpg", CamShotPathFinal, lblIDNumber.Text)),
                    new SqlParameter("@SPAction","UpdateByMemberID")
                };
                int result2 = SDDbSession.Default.FromProc("TableMemberInfo").AddParameter(sp3).ExecuteNonQuery();
                //if (result2 < 1)
                //{
                //    return false;
                //}
                //MovePhoto();
                return true;
            }
            return false;
        }

        private void MovePhoto()
        {
            if (
            File.Exists(string.Format("{0}{1}\\{2}.bmp", hidMapPath1p.Text, hidIDShotTimesnap.Text, lblIDNumber.Text)))
            {
                File.Copy(
                    string.Format("{0}{1}\\{2}.bmp", hidMapPath1p.Text, hidIDShotTimesnap.Text, lblIDNumber.Text),
                    string.Format("{0}{1}.bmp", IDShotPath, lblIDNumber.Text), true);
            }

            if (!string.IsNullOrEmpty(hidCamShotName.Text))
            {
                File.Copy(
                    string.Format("{0}{1}{2}.jpg", hidMapPath3p.Text, lblIDNumber.Text, hidCamShotTimesnap.Text),
                    string.Format("{0}{1}.jpg", CamShotPath, lblIDNumber.Text), true);
            }
        }
        #endregion

        private void RechargeInit(string initialAmount, string workAmount)
        {
            ModelLoginUser user = (ModelLoginUser)Session["LoginUser"];
            DateTime expireDate = DateTime.Now;
            if (!string.IsNullOrEmpty(lblExpireDate.Text))
            {
                expireDate = Convert.ToDateTime(lblExpireDate.Text);
            }
            SqlParameter[] sp = new SqlParameter[]{
                    new SqlParameter("@InitialAmount",Convert.ToDecimal(initialAmount)),
                    new SqlParameter("@WorkAmount",Convert.ToDecimal(workAmount)),
                    new SqlParameter("@BonusAmount",0),
                    new SqlParameter("@PlusDays",Convert.ToInt32(expireDate.Subtract(DateTime.Today).Days)),
                    new SqlParameter("@PlusTimes",0),
                    new SqlParameter("@PlusAmount",0),
                    new SqlParameter("@CreateUserID",user.UserID),
                    new SqlParameter("@MemcardNo",txtMemCardNo.Text.Trim()),
                    new SqlParameter("@PlusDays2Log",0),
                    new SqlParameter("@SPAction","Recharge")
                };
            object ds = SDDbSession.Default.FromProc("TableCardRevenue").AddParameter(sp).ToScalar();//.ExecuteNonQuery();//TODO:修改可能返回值无效
            //if (ds < 1)
            //{
            //    Alert.Show("充值失败，请返回重试！");

            //    return;
            //}
        }
        public string GetRegistID()
        {
            int count = SDDbSession.Default.From<MemberInfo>().Count();
            if (count < 1)
            {
                return "DJ00000001";
            }
            MemberInfo oldRegistID = SDDbSession.Default.From<MemberInfo>().OrderBy(MemberInfo._.MemberID.Desc).ToFirst();
            string newSerial = oldRegistID.RegistID.Substring(2).TrimStart('0');
            string newRegistID = String.Format("DJ{0}", (Convert.ToInt32(newSerial) + 1).ToString().PadLeft(8, '0'));
            return newRegistID;
        }

        protected void file_upload_FileSelected(object sender, EventArgs e)
        {
            if (file_upload.HasFile)
            {
                string fileName = file_upload.ShortFileName;
                string exName = fileName.Substring(fileName.IndexOf('.') + 1).Trim().ToLower();
                if (exName != "jpg")
                {
                    Alert.Show("只支持jpg图片");
                    return;
                }

                string server = ConfigurationManager.AppSettings["AppServer"];
                //string sDirectory = string.Format(@"\\{0}\CamShotTemp\", server);
                string sDirectory = Server.MapPath("~/Img/CamShot/");
                if (!Directory.Exists(sDirectory))
                    Directory.CreateDirectory(sDirectory);

                file_upload.SaveAs(Path.Combine(sDirectory, lblIDNumber.Text + ".jpg"));
                //imgCam.ImageUrl = Path.Combine(sDirectory, lblIDNumber.Text + hidCamShotTimesnap.Text + ".jpg");
                imgCam.ImageUrl = Path.Combine("/Img/CamShot/", lblIDNumber.Text + ".jpg");
                file_upload.Reset();

            }
        }

        private void Print()
        {
            SetPrintSession();
            PageContext.RegisterStartupScript(Window1.GetShowReference("CompanyMemberPrint.aspx", "打印办卡记录"));

        }
        private void SetPrintSession()
        {
            ModelLoginUser user = (ModelLoginUser)Session["LoginUser"];
            var mrp = new ModelCompanyMemberPrint
            {
                MemType = "企业卡",
                StartDate = lblStartDate.Text,
                ExpireDate = lblExpireDate.Text,
                InitialAmount = GetInitialAmount(),
                Worker = user.RealName,
                MemCardNo = txtMemCardNo.Text,
            };
            Session["CompanyMemberPrint"] = mrp;

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("CompanyMemberManage.aspx");
        }

        protected void txtMemCardNo_TextChanged(object sender, EventArgs e)
        {
            if (txtMemCardNo.Text.Trim().Length < 10)
            {
                lblCardLength.Text = "<span style='color:red;font-weight:bold;'>卡号少于10位</span>";
            }
            else
            {
                lblCardLength.Text = "";
            }
        }

        protected void Window2_Close(object sender, WindowCloseEventArgs e)
        {
            imgCam.ImageUrl = "/Img/CamShotTemp/" + SDLITS.Common.CacheHelper.ReadIdentify("ImgName") + ".bmp";
            SDLITS.Common.CacheHelper.RemoveIdentify("ImgName");
            SDLITS.Common.CacheHelper.RemoveIdentify("Id");
        }

        protected void hid_btn1_Click(object sender, EventArgs e)
        {
            List<string> str = StringHelper.GetSubStringList(hidCardInfo.Text, '|');
            if (str.Count > 0)
            {
                lblIDNumber.Text = str[0];
                lblName.Text = str[1];
                lblIDAddress.Text = str[2];
                lblSex.Text = str[3];
                lblBirthday.Text = str[4];//Convert.ToDateTime(str[4]).ToString("yyyy-MM-dd");
            }
            else
            {
                Alert.Show("读卡失败，请重试！");
                return;
            }
            btnCamer.OnClientClick = Window2.GetShowReference("/Driver/CameraPhoto.aspx?id=" + lblIDNumber.Text);

            ViewState["IsRead"] = true;
        }

    }
}